﻿using DataServiceDTO.DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace IDataService
{
    public interface IRemoteDB
    {
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <returns>添加条数</returns>
        int Insert<T>(T t, IDbConnection conn, IDbTransaction tran);
        /// <summary>
        /// 批量添加
        /// </summary>
        ///<returns>添加条数</returns>
        int BeatchInsert<T>(IEnumerable<T> t, IDbConnection conn, IDbTransaction tran);

        /// <summary>
        /// 更新一条数据（默认更新所有字段）
        /// </summary>
        /// <returns>更新条数</returns>
        int Update<T>(T t, IDbConnection conn, IDbTransaction tran);

        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="fieldFunc">需要更新的字段，例：x=>new{x.字段1, x.字段2}</param>
        /// <returns>更新条数</returns>
        int Update<T>(T t, Expression<Func<T, object>> fieldFunc, IDbConnection conn, IDbTransaction tran);


        /// <summary>
        /// 批量更新（默认更新所有字段）
        /// </summary>
        /// <returns>更新条数</returns>
        int BeatchUpdate<T>(IEnumerable<T> t, IDbConnection conn, IDbTransaction tran);

        /// <summary>
        /// 批量更新
        /// </summary>
        /// <returns>更新条数</returns>
        int BeatchUpdate<T>(IEnumerable<T> t, Expression<Func<T, object>> fieldFunc, IDbConnection conn, IDbTransaction tran);

        /// <summary>
        /// 删除数据
        ///支持In查找
        /// Guid[] tempArray=new Guid[]{值1,值2}
        /// string[] tempArray=new string[]{值1,值2}
        /// 例：Update<T>(x => tempArray.Contains(x.字段)|| tempArray1.Contains(x.字段));
        /// </summary>
        /// <param name="whereFunc">where条件，例：x=>new{x.字段5, x.字段6</param>
        /// <returns>删除条数</returns>
        int Delete<T>(Expression<Func<T, bool>> whereFunc, IDbConnection cnn, IDbTransaction tran);

        /// <summary>
        /// 返回单行单列的值，支持In查找
        /// Guid[] tempArray=new Guid[]{值1,值2}
        /// string[] tempArray=new string[]{值1,值2}
        /// 例：Scalar<T>(x => tempArray.Contains(x.字段)|| tempArray1.Contains(x.字段));
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="whereFunc">where条件，例：x=>new{x.字段5, x.字段6</param>
        /// <param name="cnn"></param>
        /// <param name="commandTimeout"></param>
        /// <param name="commandType"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        T ScalarCount<T>(Expression<Func<T, bool>> whereFunc, IDbConnection cnn, IDbTransaction tran, int? commandTimeout, CommandType? commandType);

        /// <summary>返回列表 </summary>
        /// <param name="whereFunc">
        /// Guid[] tempArray=new Guid[]{值1,值2}
        ///例：Query<T>(x => tempArray.Contains(x.字段)&&x.字段2=值2||x.字段3=值3);
        IEnumerable<T> Query<T>(Expression<Func<T, bool>> whereFunc, IDbConnection cnn, IDbTransaction tran, int? commandTimeout);

        Task<IEnumerable<T>> QueryAsync<T>(Expression<Func<T, bool>> whereFunc, IDbConnection cnn, IDbTransaction tran, int? commandTimeout);

        /// <summary>
        /// 返回单个实体数据
        /// </summary>
        T QueryModel<T>(Expression<Func<T, bool>> whereFunc, IDbConnection cnn, IDbTransaction tran, int? commandTimeout);

        /// <summary>
        /// 返回分页数据
        /// </summary>
        /// <exception cref="ArgumentNullException">分页参数为空抛出异常</exception>
        IEnumerable<T> QueryPage<T>(Expression<Func<T, bool>> whereFunc, RequestPageDTO requestPageDTO,out int recordCount, IDbConnection cnn, IDbTransaction tran, int? commandTimeout);

    }
}
